package module
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	public class Atom extends Sprite
	{
		private var m_object:*;			// 显示资源
		private var m_props:Dictionary;		// 属性列表
		private var m_cls:String;
		
		public function Atom(cls:String = "")
		{
			m_cls = cls;
			m_props = new Dictionary(true);
		}
		
		public function setProp(key:String,val:*):void
		{
			m_props[key] = val;
			if(m_object)
				m_object[key] = val;
		}
		
		public function set cls(v:*):void
		{
			m_cls = cls;
		}
		
		public function get cls():String
		{
			return m_cls;
		}
		
		public function set obj(v:*):void
		{
			// 保存新的资源，同时设定新资源的属性信息
			m_object = v;
			
			for (var key:String in m_props)
				m_object[key] = m_props[key];
			
			if(m_object is DisplayObject)
				addChild(m_object);
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		public function get obj():*
		{
			return m_object;
		}
		
		public function clear():void
		{
			m_props = new Dictionary(true);
			if(m_object && this.contains(m_object))
				this.removeChild(m_object);
			m_object = null;
		}
		
		public function destory():void
		{
			m_props = null;
			m_object = null;
			if(parent)parent.removeChild(this);
		}
	}
}